package main

import (
	"fmt"
	"io"
	"log"
	"net/http"
	"strings"
)

//使用go自带的http包实现方式1
func main() {
	//设置路由
	http.HandleFunc("/", sayHello)
	err := http.ListenAndServe(":8080", nil)
	if err != nil {
		log.Fatal(err)
	}
}

func sayHello(w http.ResponseWriter, r *http.Request) {
	r.ParseForm() //解释参数，默认不会解释
	fmt.Println(r.Form)
	fmt.Println("path", r.URL.Path)
	fmt.Println("scheme", r.URL.Scheme)
	fmt.Println(r.Form["url_long"])
	for k, v := range r.Form {
		fmt.Println("key", k)
		fmt.Println("value", strings.Join(v, ""))
	}
	io.WriteString(w, "Hello World, this is version 1")
}
